# -*- coding: utf-8 -*-
"""
-------------------------------------------------
File Name： num_in_one_row_template
Description :
Author : 'li'
date： 2020/11/5
-------------------------------------------------
Change Activity:
2020/11/5:
-------------------------------------------------
"""
from ml.modules.container_num_recognition.single_container_recognition.module.check_result_template.container_type_processor import \
    ContainerTypeProcessor
from ml.modules.container_num_recognition.single_container_recognition.module.gen_res.container_num_check import \
    verification_container_num


class NumInOneRowTemplate:
    def __init__(self, format_result_list):
        self.format_result_list = format_result_list
        self.company_number, self.serial_number, self.check_number = '', '', ''
        self.is_valid_container_number, self.container_type_number = False, ''

    def is_this_template(self):
        """
        is this template
        :return:
        """
        for lst in self.format_result_list:
            line_content = ''.join(lst)
            if len(line_content) == 11 and line_content[:4].isalpha() \
                    and line_content[4:10].isdecimal() and line_content[10].isdigit():
                return True
        return False

    def get_result(self):
        for lst in self.format_result_list:
            line_content = ''.join(lst)
            if len(line_content) == 11 and line_content[:4].isalpha() \
                    and line_content[4:10].isdecimal() and line_content[10].isdigit():
                company_number, serial_number, check_number = \
                    line_content[:4], line_content[4:10], line_content[10]
                self.company_number, self.serial_number, self.check_number = \
                    company_number, serial_number, check_number
                if verification_container_num(company_number, serial_number, check_number):
                    self.is_valid_container_number = True
            for item in lst:
                if len(item) == 4 and ContainerTypeProcessor(item).is_content_type():
                    self.container_type_number = item
